package machine.utils;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 消息id过滤，不重复发送
 *
 * @author zhanghui145
 * @date 2021/12/25 11:04
 * @since 1.0.0
 */
public final class MsgDequeUtils {

    private MsgDequeUtils(){}

    private static final Deque<Integer> deque = new LinkedList<>();

    public static void put(Integer messageId){
        if (deque.size() > 9) {
            deque.removeFirst();
        }
        deque.addLast(messageId);
    }

    public static boolean check(Integer messageId){
        if (messageId == null)
            return false;
        for (Integer id : deque) {
            if (messageId.equals(id)) {
                return true;
            }
        }
        return false;
    }
}